<template>
  <div>
    <div class="cart">
      <div id="topTitle">
        <div style="font-size: 20px;">{{ particularsList.product_name }}</div>
        <div>
          <span>概述</span>
          <span>参数</span>
          <span>用户评价</span>
        </div>
      </div>
    </div>
    <div class="boxBody">
      <div class="boxLeft">
        <el-carousel height="510px" width="410px" indicator-position="outside">
          <el-carousel-item v-for="item in particularsSwaper" :key="item.id">
            <img
              :src="'http://106.15.179.105:3000/' + item.product_picture"
              alt=""
            />
          </el-carousel-item>
        </el-carousel>
      </div>
      <div class="boxRight">
        <p style="font-size: 24px;">{{ particularsList.product_name }}</p>
        <p style="color: rgb(176, 176, 176);padding-top: 10px;">
          {{ particularsList.product_intro }}
        </p>
        <p style="color: rgb(255, 103, 0);padding-top: 10px;">小米自营</p>
        <div class="price">
          <span>{{ particularsList.product_selling_price }}</span>
          <span class="del">{{ particularsList.product_price }}</span>
        </div>
        <div class="pro-list">
          <span class="pro-name">{{ particularsList.product_name }}</span>
          <span class="pro-price"
            ><span>{{ particularsList.product_selling_price }}元</span
            ><span class="pro-del" style=""
              >{{ particularsList.product_price }}元</span
            ></span
          >
          <p class="price-sum">
            总计 : {{ particularsList.product_selling_price }}元
          </p>
        </div>
        <div class="button">
          <button
            type="button"
            class="el-button btnshop el-button--default"
            @click="addCart"
          >
            <span>加入购物车</span>
          </button>
          <button
            type="button"
            class="el-button btnlike el-button--default"
            @click="loveShop"
          >
            <span>喜欢</span>
          </button>
        </div>
        <div class="XMLogo">
          <ul>
            <li><i class="el-icon-circle-check"></i> 小米自营</li>
            <li><i class="el-icon-circle-check"></i> 小米发货</li>
            <li><i class="el-icon-circle-check"></i> 7天无理由退货</li>
            <li><i class="el-icon-circle-check"></i> 7天价格保护</li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import particularsAPI from "../../api/particulars";
import shoppingCartAPI from '../../api/shoppingCart'
export default {
  components: {},
  name: "",
  data() {
    return {
      id: null,
      particularsList: [],
      particularsSwaper: [],
      product_id: 0,
    };
  },
  activated() {
    this.id = this.$route.query.productID;
    this.gitListAll();
    this.gitSwaip();
  },
  created() {},
  methods: {
    async gitListAll() {
      const { data: res } = await particularsAPI.gitListAll({
        productID: this.id,
      });
      this.particularsList = res.Product[0];
      console.log(this.particularsList);
    },
    async gitSwaip() {
      let { data: res } = await particularsAPI.gitSwaip({
        productID: this.id,
      });
      this.particularsSwaper = res.ProductPicture;
      console.log(this.particularsSwaper);
    },

    //添加喜欢
    async loveShop(product_id) {
      if (this.$store.state.userName) {
      }
      let { data: res } = await particularsAPI.getAddData({
        user_id: this.$store.state.user_id,
        product_id: this.id,
      });
      console.log(res);
      if (res.code == "001") {
        this.$notify({
          message: res.msg,
          type: "success",
        });
      } else {
        this.$notify({
          message: res.msg,
          type: "error",
        });
      }
      // this.loginVisible = true;
    },
    //添加加购
    async addCart() {
      if (this.$store.state.userName) {
      }
      let { data: res } = await shoppingCartAPI.getAddList({
        user_id: this.$store.state.user_id,
        product_id: this.id,
      });
      console.log(res);
      if (res.code == "001") {
        this.$notify({
          message: res.msg,
          type: "success",
        });
      } else {
        this.$notify({
          message: res.msg,
          type: "error",
        });
      }
    },
  },
  computed: {},
  watch: {},
};
</script>

<style lang="scss" scoped>
.cart {
  width: 100%;
  height: 64px;
  #topTitle {
    width: 1225px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    div {
      span {
        margin-left: 10px;
      }
      span:hover {
        color: orangered;
      }
    }
  }
}

.boxBody {
  width: 1225px;
  margin: 0 auto;
  height: 560px;
  box-shadow: inset 0px 0px 10px #b0b0b0;
  background-color: white;
  padding: 10px 10px;
  .boxLeft {
    float: left;
    width: 560px;
    height: 560px;
    img {
      width: 550px;
      height: 550px;
    }
  }
  .boxRight {
    float: left;
    margin-left: 5px;
    width: 640px;
    .XMLogo li {
      list-style: none;
      float: left;
      margin-right: 20px;
      color: rgb(176, 176, 176);
    }
    .button {
      height: 55px;
      margin: 10px 0px 20px;
      .btnlike {
        width: 260px;
        margin-left: 40px;
        background-color: rgb(176, 176, 176);
      }
      .btnshop {
        width: 340px;
        background-color: rgb(255, 103, 0);
      }
    }
    .price {
      padding: 25px 0;
      font-size: 18px;
      color: #ff6700;
      border-bottom: solid 1px rgb(224, 224, 224);
      .del {
        font-size: 14px;
        margin-left: 10px;
        color: rgb(176, 176, 176);
        text-decoration: line-through;
      }
    }
    .pro-list {
      background: rgb(249, 249, 250);
      padding: 30px 60px;
      margin: 50px 0px;
      .pro-price {
        float: right;
      }
      .pro-name {
        line-height: 30px;
        color: rgb(97, 97, 97);
        .price-sum {
          color: rgb(255, 103, 0);
          font-size: 24px;
          padding-top: 20px;
        }
        .pro-del {
          margin-left: 10px;
          text-decoration: line-through;
        }
      }
    }
  }
}
</style>